﻿using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
using System.Collections.Generic;
using zdzh.zdmgr.COL;
using zdzh.zdmgr.SFL;

namespace zdzh.zdmgr.DAL.OleDb
{
    /// <summary>
    /// 对象名称：回迁房照OleDb数据访问子类（数据访问层）
    /// 对象说明：提供“回迁房照类（业务逻辑层）”针对OleDb的“增删改查”等各种数据访问方法，继承通用数据访问父类。
    /// 调用说明：通常不需要直接实例化本类，而使用“回迁房照类（业务逻辑层）”中的DataAccess属性来调用本类所实现的方法。
    /// 作者姓名：飞翔熊
    /// 编写日期：2012-12-3 13:23:04
    /// </summary>
    public class HuiqianfangzhaoDAL:DAL.Common.HuiqianfangzhaoDAL
    {
        #region EasyCode所生成的默认代码
        //﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉
        //  此区域的代码为EasyCode所自动生成，实现了父类中定义的抽象方法。请不要直接修改该区域中的任何代码，   
        //  或在该区域中添加任何自定义代码，当该类发生变更时，您可以随时使用EasyCode重新生成覆盖其中的代码。  
        //﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍


        /// <summary>
        /// 将回迁房照（Huiqianfangzhao）数据，采用INSERT操作插入到数据库中，并返回受影响的行数。
        /// </summary>
        /// <param name="huiqianfangzhao">回迁房照（Huiqianfangzhao）实例对象</param>
        public override int Insert(Huiqianfangzhao huiqianfangzhao)
        {
            int index = SFL.OleDbHelper.GetMaxIndex("huiqianfangzhao")+1;
            string sqlText = "INSERT INTO [huiqianfangzhao]"
                           + "([index],[xieyihao],[chanquanren],[pingguhao],[fangzhaohao],[donghao],[mianji])"
                           + "VALUES"
                           + "(@index,@xieyihao,@chanquanren,@pingguhao,@fangzhaohao,@donghao,@mianji)";
            OleDbParameter[] parameters = 
            {
                new OleDbParameter("@index"     , OleDbType.Integer , 4){ Value = index },
                new OleDbParameter("@xieyihao"    , OleDbType.Integer  , 4 ){ Value = huiqianfangzhao.Xieyihao    },
                new OleDbParameter("@chanquanren" , OleDbType.VarWChar , 50){ Value = huiqianfangzhao.Chanquanren },
                new OleDbParameter("@pingguhao"   , OleDbType.VarWChar , 50){ Value = huiqianfangzhao.Pingguhao   },
                new OleDbParameter("@fangzhaohao" , OleDbType.VarWChar , 50){ Value = huiqianfangzhao.Fangzhaohao },
                new OleDbParameter("@donghao"     , OleDbType.VarWChar , 50){ Value = huiqianfangzhao.Donghao     },
                new OleDbParameter("@mianji"      , OleDbType.Decimal  , 9 ){ Value = huiqianfangzhao.Mianji      }
            };
            SFL.OleDbHelper.ExecuteNonQuery(sqlText, parameters);
            return index;
        }


        /// <summary>
        /// 将回迁房照（Huiqianfangzhao）数据，根据主键“协议号（Xieyihao）”采用UPDATE操作更新到数据库中，并返回受影响的行数。
        /// </summary>
        /// <param name="huiqianfangzhao">回迁房照（Huiqianfangzhao）实例对象</param>
        public override int Update(Huiqianfangzhao huiqianfangzhao)
        {
            string sqlText = "UPDATE [huiqianfangzhao] SET "
                           + "[xieyihao]=@xieyihao,[chanquanren]=@chanquanren,[pingguhao]=@pingguhao,[fangzhaohao]=@fangzhaohao,[donghao]=@donghao,[mianji]=@mianji "
                           + "WHERE [index]=@index";
            OleDbParameter[] parameters = 
            {
                new OleDbParameter("@xieyihao"    , OleDbType.Integer  , 4 ){ Value = huiqianfangzhao.Xieyihao    },
                new OleDbParameter("@chanquanren" , OleDbType.VarWChar , 50){ Value = huiqianfangzhao.Chanquanren },
                new OleDbParameter("@pingguhao"   , OleDbType.VarWChar , 50){ Value = huiqianfangzhao.Pingguhao   },
                new OleDbParameter("@fangzhaohao" , OleDbType.VarWChar , 50){ Value = huiqianfangzhao.Fangzhaohao },
                new OleDbParameter("@donghao"     , OleDbType.VarWChar , 50){ Value = huiqianfangzhao.Donghao     },
                new OleDbParameter("@mianji"      , OleDbType.Decimal  , 9 ){ Value = huiqianfangzhao.Mianji      },
                new OleDbParameter("@index"    , OleDbType.Integer  , 4 ){ Value = huiqianfangzhao.Index    }
            };
            return SFL.OleDbHelper.ExecuteNonQuery(sqlText, parameters);
        }


        /// <summary>
        /// 根据回迁房照（Huiqianfangzhao）的主键“协议号（Xieyihao）”采用DELETE操作从数据库中删除相关记录，并返回受影响的行数。
        /// </summary>
        /// <param name="xieyihao">回迁房照（Huiqianfangzhao）的主键“协议号（Xieyihao）”</param>
        public override int Delete(int xieyihao)
        {
            string sqlText = "DELETE FROM [huiqianfangzhao] "
                           + "WHERE [index]=@xieyihao";
            OleDbParameter[] parameters = 
            {
                new OleDbParameter("@xieyihao" , OleDbType.Integer , 4){ Value = xieyihao }
            };
            return SFL.OleDbHelper.ExecuteNonQuery(sqlText, parameters);
        }


        /// <summary>
        /// 根据回迁房照（Huiqianfangzhao）的主键“协议号（Xieyihao）”从数据库中获取回迁房照（Huiqianfangzhao）的实例。
        /// 成功从数据库中取得记录返回新回迁房照（Huiqianfangzhao）的实例“，没有取到记录返回null值。
        /// </summary>
        /// <param name="xieyihao">回迁房照（Huiqianfangzhao）的主键“协议号（Xieyihao）”</param>
        public override List<Huiqianfangzhao> GetDataByXieyihao(int xieyihao)
        {
            string sqlText = "SELECT * "
                           + "FROM [huiqianfangzhao]"
                           + "WHERE [xieyihao]=@xieyihao";
            OleDbParameter[] parameters = 
            {
                new OleDbParameter("@xieyihao" , OleDbType.Integer , 4){ Value = xieyihao }
            };
            List<Huiqianfangzhao> list = new List<Huiqianfangzhao>();
            OleDbDataReader oleDbDataReader = SFL.OleDbHelper.ExecuteReader(sqlText, parameters);
            while (oleDbDataReader.Read())
            {
                Huiqianfangzhao huiqianfangzhao = new Huiqianfangzhao();
                ReadHuiqianfangzhaoAllData(oleDbDataReader, huiqianfangzhao);
                list.Add(huiqianfangzhao);
            }
            oleDbDataReader.Close();
            return list;
        }
        public override Huiqianfangzhao GetDataByIndex(int xieyihao)
        {
            Huiqianfangzhao huiqianfangzhao = null;
            string sqlText = "SELECT * "
                           + "FROM [huiqianfangzhao] "
                           + "WHERE [index]=@xieyihao";
            OleDbParameter[] parameters = 
            {
                new OleDbParameter("@xieyihao" , OleDbType.Integer , 4){ Value = xieyihao }
            };

            OleDbDataReader oleDbDataReader = SFL.OleDbHelper.ExecuteReader(sqlText, parameters);
            if (oleDbDataReader.Read())
            {
                huiqianfangzhao = new Huiqianfangzhao();
                ReadHuiqianfangzhaoAllData(oleDbDataReader,huiqianfangzhao);
            }
            oleDbDataReader.Close();
            return huiqianfangzhao;
        }


        /// <summary>
        /// 从数据库中读取并返回所有回迁房照（Huiqianfangzhao）List列表。
        /// </summary>
        public override List<Huiqianfangzhao> GetAllList()
        {
            string sqlText = "SELECT * "
                           + "FROM [huiqianfangzhao]";
            List<Huiqianfangzhao> list = new List<Huiqianfangzhao>();
            OleDbDataReader oleDbDataReader = SFL.OleDbHelper.ExecuteReader(sqlText, null);
            while (oleDbDataReader.Read())
            {
                Huiqianfangzhao huiqianfangzhao = new Huiqianfangzhao();
                ReadHuiqianfangzhaoAllData(oleDbDataReader, huiqianfangzhao);
                list.Add(huiqianfangzhao);
            }
            oleDbDataReader.Close();
            return list;
        }


        /// <summary>
        /// 根据每页记录数及所要获取的页数，从数据库中读取并返回经过分页后的回迁房照（Huiqianfangzhao）的列表及分页信息。
        /// 该方法所获取的回迁房照（Huiqianfangzhao）列表仅用于在数据控件中显示，该方法只为对象中需要显示的属性进行赋值。
        /// </summary>
        public override PageData GetPageList(int pageSize, int curPage)
        {
            string sqlText = "SELECT * "
                           + "FROM [huiqianfangzhao]";
            List<Huiqianfangzhao> list = new List<Huiqianfangzhao>();
            OleDbDataReader oleDbDataReader = SFL.OleDbHelper.ExecuteReader(sqlText, null);

            PageData pageData = new PageData();
            pageData.PageSize = pageSize;
            pageData.CurPage = curPage;
            pageData.RecordCount = 0;
            pageData.PageCount = 1;

            int first = (curPage - 1) * pageSize + 1;
            int last = curPage * pageSize;

            while (oleDbDataReader.Read())
            {
                pageData.RecordCount++;
                if (pageData.RecordCount >= first && last >= pageData.RecordCount)
                {
                    Huiqianfangzhao huiqianfangzhao = new Huiqianfangzhao();
                    ReadHuiqianfangzhaoPageData(oleDbDataReader, huiqianfangzhao);
                    list.Add(huiqianfangzhao);
                }
            }
            oleDbDataReader.Close();

            if(pageData.RecordCount>0)
                pageData.PageCount = Convert.ToInt32(Math.Ceiling((double)pageData.RecordCount / (double)pageSize));

            pageData.PageList = list;
            return pageData;
        }

        #endregion EasyCode所生成的默认代码

        //﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉
        //  说明：以下区域的代码为设计开发人员所编写，主要为扩展该数据访问类的功能，而定义的变量、属性及相关数据访问方法。  
        //  注意：为了保证该项目的多数据库支持与扩展性，请先在本类的父类中对相关抽象方法进行定义，再在本类中进行具体实现。
        //﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍










    }
}
